/************************更新动态制作js*********************************/
define(function(require, exports, module) {
	
	var $ = require("jquery1.7");
	var utils = require("utils");
	var ui = require("ui");
	var ctx = utils.constants.ctx;
	var Validator = require("validator");
	var ueditor = require("ueditor");
	var webTrendService = require("bean/webTrendService");
	var BlackBox = require("blackbox");
	var blackBox = new BlackBox();
	
	var validator ;
	
	var con_validator = new Validator({
        element: $("#webTrendsUpdateForm")
    }).addItem({
        element: '[name=webTrendsTitle]',
        required: true
    });
	
	$("#sureAddwebTrendsBtn").bind("click",function(){
		//notice_editor : 前端u_editor创建的对象
		var webTrendsTitle=$("#webTrendsTitle").val();
		if(webTrendsTitle==""){
			blackBox.alert("请输入标题");
			return;
		}
		var webTrendsPublisher=$("#webTrendsPublisher").val();
		if(webTrendsPublisher==""){
			blackBox.alert("请输入发布人");
			return;
		}
		
		var webTrends_content = webTrends_editor.getContent();
		if(webTrends_content==""){
			blackBox.alert("请输入公告内容");
			return;
		}
		
		// 公告实体
		var webTrends = {
				title : webTrendsTitle,
				publisher : webTrendsPublisher,
				content : webTrends_content
		}
		var webTrendsIdInput=$("#webTrendsIdInput").val();
		try{
			if(webTrendsIdInput==null || ""==webTrendsIdInput){
				webTrendService.addWebTrends(webTrends);
				blackBox.alert("添加成功",function(){
					location.href = ctx + "/back/website/webTrendsManager";
				},{
					title:'提示',
					value:'确认'
				});
			}else{
				webTrends["id"]=webTrendsIdInput;
				webTrendService.updateWebTrends(webTrends);
				blackBox.alert("修改成功");
				location.href = ctx + "/back/website/webTrendsManager";
			}
			
			
		}catch(e){
			alert(e.message);
		}
	});
	
	//取消按钮
	$("#cancelAddwebTrendsBtn").bind("click",function(){
		blackBox.confirm("确定要取消所有操作？",function(data){
			if(data){
				location.href = ctx + "/back/website/webTrendsManager";
			}
		},{
			title:'提示',
			value:'确认'
		});
		
	});
	
});